package nc.oa.login;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;

public class BoTransTools {
	public static BaseDAO dao;
	
	public static BaseDAO getBaseDao() {
		if(dao == null) {
			dao = new BaseDAO();
		}
		return dao;
	}
	
	/**
	 * 根据编码翻译成主�?
	 * @param vo
	 * @param condition 条件，形�?  code = '001'
	 * @return 
	 * @throws BusinessException
	 * @throws Exception 
	 * @throws InstantiationException 
	 */
	public static String transCodeToPk(Class className,String condition) throws Exception {
		List<SuperVO> values = (List<SuperVO>) getBaseDao().retrieveByClause(className.newInstance().getClass(), condition);
		if(values == null || values.size() == 0) {
			return null;
		}else {
			return values.get(0).getPrimaryKey();
		}
	}
	
	/**
	 * 根据编码翻译自定义档案主�?
	 * @param deflistcode 
	 * @param doccode
	 * @return
	 * @throws BusinessException
	 */
	public static String transDefDocByCode(String deflistcode,String doccode) throws BusinessException {
		StringBuffer query_def = new StringBuffer();
		query_def.append("select b.pk_defdoc from bd_defdoclist a \n");
		query_def.append("inner join bd_defdoc b on a.pk_defdoclist = b.pk_defdoclist \n");
		query_def.append("where a.code = '"+ deflistcode +"' and b.code = '"+ doccode +"' \n");
		String pk_doc = (String) new BaseDAO().executeQuery(query_def.toString(), new ColumnProcessor());
		
		return pk_doc;
	}
	
	/**
	 * 查询oa单点与交易类型对照表
	 * 
	 * @return
	 * @throws BusinessException
	 */
	@SuppressWarnings("unchecked")
	public static Map<String, String> queryOABillTypeContrast() throws BusinessException {
		// oa单点与交易类型对照表
		List<DefdocVO> constrastList = (List<DefdocVO>) new BaseDAO().retrieveByClause(DefdocVO.class,
				" pk_defdoclist = (select pk_defdoclist from bd_defdoclist where code = 'EK100') and enablestate = 2 ");
		Map<String, String> contrastMap = new HashMap<>();
		
//		这里配置了url到自定义档案里面，按照交易类型进行配�?
//		形如�?
//		ifr=%252Fnccloud%252Fresources%252Fuap%252Fmsgcenter%252Fmessage%252FapproveDetail%252Findex.html%2523%252F%253Fpk_message%253Doaparam1%2526pageMsgType%253Doaparam2%2526devModule%253Derm%2526c%253D201102BXSP%2526p%253D201102BTYF_C%2526n%253D%25E9%2580%259A%25E7%2594%25A8%25E6%258A%25A5%25E9%2594%2580%25E5%258D%2595%25E5%25AE%25A1%25E6%2589%25B9%2526appcode%253D10160501%2526pagecode%253D10160501APPROVE%2526avatarName%253D%25E6%25B5%25A9%2526avatarColor%253Dchengse%2526msgType%253Dapprove%2526isread%253DY%2526startTime%253D%2526endTime%253D%2526msgsourcetype%253D%2526billtype%253D%2526billno%253D%2526content%253D%2526sortMessage%253Dfalse%2526sender%253D%2524%255E%2524%2526commiter%253D%2524%255E%2524%2526orgRestore%253D0%2526custom%253D%257B%2522pk_group%2522%253A%25220001A810000000000UV8%2522%257D=10160501=10160501APPROVE=0001Z0100000000042SD=%25E5%25AE%25A1%25E6%2589%25B9%25E4%25B8%25AD%25E5%25BF%2583=%25E5%258A%25A8%25E6%2580%2581%25E5%25BB%25BA%25E6%25A8%25A1%25E5%25B9%25B3%25E5%258F%25B0=%25E6%25B5%2581%25E7%25A8%258B%25E7%25AE%25A1%25E7%2590%2586=%25E5%25AE%25A1%25E6%2589%25B9%25E7%25AE%25A1%25E7%2590%2586
		contrastMap = constrastList.stream().collect(Collectors.toMap(e -> e.getCode(), e -> e.getCode()));
		return contrastMap;
	}

}
